/**
 * 用户注册-填写账号信息
 * @param mobile 用户输入手机号
 * @param password 用户输入密码
 * @param name 用户输入用户名
 * @param code 校验码
 */
function ajaxRegisterForLogin(mobile, password, name, code) {
    var url = "/Lvscore_User_M/register/ajaxRegisterForLogin";
    $.post(url, {
        mobile: mobile,
        password: password,
        name: name,
        code: code
    }, function (data) {
        /*成功：ok
         失败：系统异常*/
        var cookie = new sweetCookie();
        if (data == 1) {
            //cookie.setCookie("tel","",-1);
            window.location.href = "/Lvscore_User_M/userWeb/views/register/registerTip.html";
        } else if (data == -1) {
            //cookie.setCookie("tel","",-1);
            alertBox("注册异常，请重试");
            setTimeout('window.location.href = "/Lvscore_User_M/userWeb/views/register/registerTel.html"', 2000);
        } else {
            alertBox("服务器异常，请重试");
            setTimeout('window.location.reload()', 1500);
        }
    })
}
$(function () {
    getUrl("register/registerTel");
    $("input").not("#next").val("");
    //实时监控输入框
    inputChange(".nickname","#nameError");
    inputChange("#password","#loginPsdError1");
    inputChange("#confirm_password","#loginPsdError2");
    inputChange("#password","#defrentError");
    inputChange("#confirm_password","#defrentError");
    //取出tel当中的值
    var cookie = new sweetCookie();
    var tel = decodeBase64(cookie.getCookie("tel"), 2).split(":")[0];
    var code = decodeBase64(cookie.getCookie("tel"), 2).split(":")[1];
    $(".tel").html(tel);
    function loginPsdMessage1(){
        var password = $("#password").val();
        if(password==null||password==""){
            validateSpanMsg("loginPsdError1","请输入登录密码");
            return false;
        }else if (!isPassword(password)) {
            validateSpanMsg("loginPsdError1","密码格式不正确");
            return false;
        }else{
            return true;
        }
    }
    function loginPsdMessage2(){
        var confirm_password = $("#confirm_password").val();
        var password = $("#password").val();
        if(confirm_password==null||confirm_password==""){
            validateSpanMsg("loginPsdError2","请确认登录密码");
            return false;
        }else if (password != confirm_password) {
            validateSpanMsg("defrentError","两次输入密码不一致");
            return false;
        }else{
            return true;
        }
    }
    function nameMessage(){
        var nickname = $(".nickname").val();
        if (nickname == null || nickname == "") {
            validateSpanMsg("nameError","请输入用户昵称");
            return false;
        }else if (!isName(nickname)) {
            validateSpanMsg("nameError","昵称格式错误");
            return false;
        }else{
            return true;
        }
    }
    $(".nickname").blur(function(){
        nameMessage();
    })
    $("#password").blur(function(){
        loginPsdMessage1();
    })
    $("#confirm_password").blur(function(){
        loginPsdMessage2();
    })
    $("#next").click(function () {
        var nickname = $(".nickname").val();
        var password = $("#password").val();
        var confirm_password = $("#confirm_password").val();
        //if (nickname == null || nickname == "") {
        //    validateSpanMsg("nameError","请输入用户昵称");
        //    return false;
        //}else if (!isName(nickname)) {
        //    validateSpanMsg("nameError","昵称格式错误");
        //    return false;
        //}
        //else if(password==null||password==""){
        //    validateSpanMsg("loginPsdError1","请输入登录密码");
        //    return false;
        //}else if(confirm_password==null||confirm_password==""){
        //    validateSpanMsg("loginPsdError2","请确认登录密码");
        //    return false;
        //}else if (!isPassword(password)) {
        //    validateSpanMsg("defrentError","密码格式不正确");
        //    return false;
        //} else if (password != confirm_password) {
        //    validateSpanMsg("defrentError","两次输入密码不一致");
        //    return false;
        //} else{
        //ajaxRegisterForLogin(tel, password, nickname, code);
    //}
         if(loginPsdMessage1()&&loginPsdMessage2()&&nameMessage()){
            ajaxRegisterForLogin(tel, password, nickname, code);
        }
    })
});
